package com.itheima.service.impl.store;

import com.itheima.mapper.store.BrokenMapper;
import com.itheima.service.store.BrokenService;
import com.itheima.utils.MapperUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;
import java.util.List;

public class BrokenServiceImpl implements BrokenService {

    /*@Override
    public int list() {
        BrokenMapper mapper = MapperUtil.getMapper(BrokenMapper.class);
        System.out.println(mapper.findNum());
        return mapper.findNum();
    }

    @Override
    public void save(MemberNum memberNum) {
        BrokenMapper mapper = MapperUtil.getMapper(BrokenMapper.class);

        memberNum.setNum(String.valueOf(mapper.findNum()));
        memberNum.setId(IdUtil.getId());
        memberNum.getDate(new Date());
        mapper.saveNum(memberNum);
    }*/

    @Override
    public List<Integer> findMemberCountByMonth(List<String> months) {
        SqlSession session = MapperUtil.getSession();
        BrokenMapper mapper = session.getMapper(BrokenMapper.class);
        List<Integer> list = new ArrayList<>();
        for(String m : months){
            m = m + "-31";//格式：2019-04-31
            Integer count = mapper.findMemberCountBeforeDate(m);
            list.add(count);
        }
        MapperUtil.close(session);
        return list;
    }
}
